package com.gitee.wsl.compose.mvi.ui.card

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.gitee.wsl.compose.mvi.component.InteractionSourceSlotProjector


class CardProjector(
    interactor: CardInteractor = CardInteractor.Default,
    presenter: CardPresenter = CardPresenter.Default
) : InteractionSourceSlotProjector<CardInteractor, CardPresenter,Unit>(interactor, presenter) {

    @Composable
    override fun body(
        combinedModifier: Modifier,
        interactor: CardInteractor,
        presenter: CardPresenter,
        interactionSource: MutableInteractionSource,
        slot: @Composable Unit.() -> Unit,
    ) {
        if (interactor.onClick == null) {
            Card(
                modifier = combinedModifier,
                shape = presenter.shape,
                colors = CardDefaults.cardColors().copy(
                    containerColor = presenter.backgroundColor,
                    contentColor =presenter.contentColor
                ),
                border = presenter.border,
                elevation = CardDefaults.elevatedCardElevation(defaultElevation = presenter.elevation),
                content = {slot(Unit)}
            )
        } else {
            Card(
                onClick = interactor.onClick,
                modifier = combinedModifier,
                enabled = interactor.enabled,
                shape = presenter.shape,
                colors = CardDefaults.cardColors().copy(
                    containerColor = presenter.backgroundColor,
                    contentColor =presenter.contentColor
                ),
                border = presenter.border,
                elevation = CardDefaults.elevatedCardElevation(defaultElevation = presenter.elevation),
                interactionSource = interactionSource,
                content = {slot(Unit)}
            )
        }
    }
}